<template>
    <section>
        <div class="cate-container">
            <div class="header flex-box flex-box-display">
                <h4>积分记录</h4>
            </div>
            <div class="cate-search flex-box">
                <el-input v-model="usersName" placeholder="搜索微信昵称"></el-input>
                <el-button type="primary" @click="searchItem">搜索</el-button>
            </div>
            <div class="cate-con">
                <el-table ref="multipleTable" :data="integralLogs" style="width: 100%">
                    <el-table-column :resizable="false" label="id">
                        <template slot-scope="scope">
                            <span>{{scope.row.id}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :resizable="false" label="用户昵称">
                        <template slot-scope="scope">
                            <span>{{scope.row.nickname}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :resizable="false" label="类型">
                        <template slot-scope="scope">
                            <span>{{scope.row.type === 1 ? '增加' : '减少'}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :resizable="false" label="增加类型">
                        <template slot-scope="scope">
                            <span>{{scope.row.sex}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :resizable="false" label="下线名称">
                        <template slot-scope="scope">
                            <span>{{scope.row.city}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :resizable="false" label="名称">
                        <template slot-scope="scope">
                            <span>{{scope.row.title}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :resizable="false" label="分数">
                        <template slot-scope="scope">
                            <span>{{scope.row.amount}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :resizable="false" label="剩余">
                        <template slot-scope="scope">
                            <span>{{scope.row.calculate}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :resizable="false" label="时间">
                        <template slot-scope="scope">
                            <span>{{scope.row.created_at}}</span>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="pagination" v-if="page.total">
                <div class="pagination-item">
                    <el-pagination layout="prev, pager, next" :total="page.total" :page-size="pageSize"
                                   @current-change="handleCurrentChange">
                    </el-pagination>
                </div>
            </div>
        </div>
    </section>
</template>

<script>

    export default {
        data() {
            return {
                usersName:'',
                integralLogs: [],
                page: {
                    total: null
                },
                pageSize: 20,
                currentRow: null
            }
        },
        watch: {},
        computed: {},
        mounted() {
            this.getIntegralLogsList();
        },
        methods: {
            searchItem() {
                console.log('usersName', this.usersName)
                axios
                    .get('admin_integral_logs', {
                        params: {
                            usersName: ['like', `%${this.usersName}%`],
                        }
                    })
                    .then(res => res.data.data)
                    .then(res => {
                        console.log('数据', res)
                        this.integralLogs = res;
                        this.tableLoading = false;
                    })
            },
            getIntegralLogsList(pagination = 1) {
                axios
                    .get('admin_users', {
                        params: {
                            pagination,
                            pageSize: this.pageSize
                        }
                    })
                    .then(res => {
                        this.page.total = res.data.count;
                        return res;
                    })
                    .then(res => res.data.data)
                    .then(res => {
                        console.log('数据', res)
                        this.integralLogs = res;
                        this.tableLoading = false;

                    })
            },
            handleCurrentChange(current) {
                this.getIntegralLogsList(current);
            }
        }
    }
</script>
<style scoped>
    .cate-container {
        margin: 25px;
        border-radius: 4px;
        background: #fff;
        min-height: calc(100vh - 92px);
    }

    .flex-box {
        display: flex;
    }

    .flex-box-display {
        justify-content: space-between;
    }

    .header {
        padding: 10px;

        border-bottom: 1px solid #d8d8d8;
    }

    .cate-search {
        padding: 10px 30px 0 30px;
    }

    .cate-con {
        min-height: 100vh;
        padding: 5px 20px 20px 20px;
    }

    .pagination {
        display: flex;
        align-items: center;
        justify-content: space-around;

        width: 100%;
    }

    el-dialog {
        line-height: 40px;
    }
</style>